import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx/pages/home/index.dart';
import 'package:getx/pages/index.dart';
import 'package:getx/pages/main/widgets/appBottomNavigation.dart';
import 'package:getx/pages/order/index.dart';

class MainPage extends GetView<MainController> {
  const MainPage({super.key});

  // 主视图
  Widget _buildView() {
    return GetBuilder<MainController>(
        builder: (controller) => Scaffold(
            body: IndexedStack(
              index: controller.cindex,
              children: const [
                HomePage(),
                OrderPage(),
                MinePage(),
              ],
            ),
            bottomNavigationBar: AppBottomNavigation(
              currentIndex: controller.cindex,
              onTapped: (index) async {
                controller.onSelectTab(index);
              },
            )));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainController>(
      init: MainController(),
      id: "main",
      builder: (_) {
        return _buildView();
      },
    );
  }
}
